package com.spring.cn.version;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName SpringV2
 * @Description : 手写SpringIOC  初始版本
 * @Author : LiangT
 * @Date : 2020/5/15 16:56
 */
public class SpringV2 extends HttpServlet {
    private Map IOC = new HashMap();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        运行阶段
//        根据URL,完成调
        doDispatch(req,resp);
    }

    private void doDispatch(HttpServletRequest req, HttpServletResponse resp) {
    }

    /**
     * 初始化阶段
     * @param config
     * @throws ServletException
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
       //  1 加载配置文件
        doLoadConfig(config.getInitParameter(""));
        // 2 初始化IOC容器

        // 3 初始化扫描到的类，并创建实例保存到IOC容器中
        doInstance();

        //=============== DI ==================
        // 4 完成DI--依赖注入
        doAotuwrite();

        /***************** MVC ********************/
        // 5 初始化HandMappering
        doInitHandermapping();

        // 6 启动
        System.out.println("Spring Farmwork Running!");
    }

    private void doInitHandermapping() {
    }

    private void doAotuwrite() {
    }

    private void doInstance() {
    }

    /**
     * 加载配置文件
     * @param initParameter
     */
    private void doLoadConfig(String initParameter) {

    }


}
